package com.micahellou.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.palic.sales.pub.mit.util.yihaodian.SignHelper;

public class IndexServlet extends HttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 197103637814956837L;

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		request.setCharacterEncoding("UTF-8");
		String result="michael lou is here!";
		String[] urls=new String[6];
		String name=request.getParameter("name");
		String uid=request.getParameter("uid");
		String mobile=request.getParameter("mobile");
		String idCard=request.getParameter("idCart");
		SignHelper helper=new SignHelper();
		helper.setTest2();
		 try {
			urls[0]=helper.getBoughtUrl(name, uid, mobile, idCard);
			urls[1]=helper.getMyOrderUrl(name, uid, mobile, idCard);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			request.setAttribute("errorMsg", e.toString());
		}
		 urls[2]=helper.getBatchOrderUrl("2010-07-25 9:00:00", "2010-08-30 19:00:35", "pingan3g");
		
		//-------------daily test----------------------------------------------
		 helper.setTest();
		try {
			urls[3] = helper.getBoughtUrl(name, uid, mobile, idCard);
			urls[4] = helper.getMyOrderUrl(name, uid, mobile, idCard);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			request.setAttribute("errorMsg", e.toString());
		}
		urls[5]=helper.getBatchOrderUrl("2010-07-25 19:00:34", "2010-08-30 19:00:35", "pingan3g");
		
		
		RequestDispatcher dispatcher = request
				.getRequestDispatcher("index.ftl");
		request.setAttribute("result", result);
		request.setAttribute("urls", urls);
//		Object ob=request.getSession().getAttribute("userrolestr");
//		HttpSession session=(HttpSession) request.getSession().getServletContext().getContext("/metaSession");
//		ServletConfig config=
//			getServletConfig();//config.getServletContext().getContext("/metaSession")
//		HttpSession session=(HttpSession) config.getServletContext().getContext("/metaSession");
//		Object ob=session.getAttribute("userrolestr");
//		if(null!=ob){
//			String[] role=request.getSession().getAttribute("userrolestr").toString().split(",");
//			request.setAttribute("role", role[0]);
//		}else{
//			request.setAttribute("role", "failed!");
//		}
		dispatcher.forward(request, response);
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		doPost(request, response);
	}
	
}
